package a51qindian.com.comprehensive.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.li.utils.TransformUtil;
import com.li.widget.DoubleTextView;

import java.util.List;

import a51qindian.com.comprehensive.R;
import a51qindian.com.comprehensive.model.ShopDeviceInfo;
import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Author: Li
 * Date: 2017/10/25 0025
 * Description:
 */

public class ShopDeviceAdapter extends RecyclerView.Adapter<ShopDeviceAdapter.ShopDeviceHolder> {


    private LayoutInflater mInflater;

    public void setShopDeviceInfoList(List<ShopDeviceInfo> shopDeviceInfoList) {
        mShopDeviceInfoList = shopDeviceInfoList;
        notifyDataSetChanged();
    }

    private List<ShopDeviceInfo> mShopDeviceInfoList;

    public ShopDeviceAdapter(Context context) {
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public ShopDeviceHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.item_shop_device, parent, false);
        return new ShopDeviceHolder(view);
    }

    @Override
    public void onBindViewHolder(ShopDeviceHolder holder, int position) {
        ShopDeviceInfo info = mShopDeviceInfoList.get(position);
        holder.mTxtNum.setTxtRight(info.getSn());
        holder.mTxtTime.setTxtRight(TransformUtil.timeFormat(info.getAddtime()));
        switch (info.getStatus()) {
            case "1":
                holder.mTxtStatus.setTxtRight("未使用");
                holder.mTxtStatus.setRightTxtDrawableRight(R.drawable.ic_device_state_unused);
                break;
            case "2":
                holder.mTxtStatus.setTxtRight("使用中");
                holder.mTxtStatus.setRightTxtDrawableRight(R.drawable.ic_device_state_using);

                break;
            case "3":
                holder.mTxtStatus.setTxtRight("损坏");
                holder.mTxtStatus.setRightTxtDrawableRight(R.drawable.ic_device_state_damage);

                break;
        }
    }

    @Override
    public int getItemCount() {
        return mShopDeviceInfoList == null ? 0 : mShopDeviceInfoList.size();
    }

    static class ShopDeviceHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.txt_num)
        DoubleTextView mTxtNum;
        @BindView(R.id.txt_status)
        DoubleTextView mTxtStatus;
        @BindView(R.id.txt_time)
        DoubleTextView mTxtTime;

        public ShopDeviceHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
